package com.ruoyi.medical.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.medical.domain.MedicineOrderItem;
import com.ruoyi.medical.service.IMedicineOrderItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 药品订单管理Controller
 * 
 * @author WGH
 * @date 2025-08-13
 */
@RestController
@RequestMapping("/medical/medicineOrderItem")
public class MedicineOrderItemController extends BaseController
{
    @Autowired
    private IMedicineOrderItemService medicineOrderItemService;

    /**
     * 查询药品订单管理列表
     */
    @PreAuthorize("@ss.hasPermi('medical:medicineOrderItem:list')")
    @GetMapping("/list")
    public TableDataInfo list(MedicineOrderItem medicineOrderItem)
    {
        startPage();
        List<MedicineOrderItem> list = medicineOrderItemService.selectMedicineOrderItemList(medicineOrderItem);
        return getDataTable(list);
    }

    /**
     * 导出药品订单管理列表
     */
    @PreAuthorize("@ss.hasPermi('medical:medicineOrderItem:export')")
    @Log(title = "药品订单管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MedicineOrderItem medicineOrderItem)
    {
        List<MedicineOrderItem> list = medicineOrderItemService.selectMedicineOrderItemList(medicineOrderItem);
        ExcelUtil<MedicineOrderItem> util = new ExcelUtil<MedicineOrderItem>(MedicineOrderItem.class);
        util.exportExcel(response, list, "药品订单管理数据");
    }

    /**
     * 获取药品订单管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('medical:medicineOrderItem:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(medicineOrderItemService.selectMedicineOrderItemById(id));
    }

    /**
     * 新增药品订单管理
     */
    @PreAuthorize("@ss.hasPermi('medical:medicineOrderItem:add')")
    @Log(title = "药品订单管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MedicineOrderItem medicineOrderItem)
    {
        return toAjax(medicineOrderItemService.insertMedicineOrderItem(medicineOrderItem));
    }

    /**
     * 修改药品订单管理
     */
    @PreAuthorize("@ss.hasPermi('medical:medicineOrderItem:edit')")
    @Log(title = "药品订单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MedicineOrderItem medicineOrderItem)
    {
        return toAjax(medicineOrderItemService.updateMedicineOrderItem(medicineOrderItem));
    }

    /**
     * 删除药品订单管理
     */
    @PreAuthorize("@ss.hasPermi('medical:medicineOrderItem:remove')")
    @Log(title = "药品订单管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(medicineOrderItemService.deleteMedicineOrderItemByIds(ids));
    }
}
